package org.ljx.taobao.controller;

import org.ljx.taobao.api.IUserService;
import org.ljx.taobao.api.entity.User;
import org.ljx.taobao.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;

/**
 * @Author: Ljx
 * @Date: 2021/12/31 11:54
 * @role: 修改密码
 */
@WebServlet("/change")
public class ChangeServlet extends HttpServlet {
    static boolean x;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        String name = req.getParameter("uname");
        String paw = req.getParameter("upaw");
        String num = req.getParameter("phone");

        if (Objects.equals(name, "") || Objects.equals(paw, "") || Objects.equals(num, "")) {
            req.setAttribute("msg", "输入的值不能为空！！！");
            req.getRequestDispatcher("change.jsp").forward(req, resp);
        } else {
            User user1 = new User(name, paw, num);
            IUserService iUserService = new UserServiceImpl();
            try {
                x = iUserService.change(user1);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            resp.sendRedirect("panduan1.jsp");
        }
    }

    public static boolean x() {
        return x;
    }
}

